import { PetMingItemData } from "../info/PetMingItemData";
import { GlobalClass } from "../../../../../com/mui/core/GlobalClass";
import { ImagesConst } from "../../../resource/ImagesConst";
import { SPetInfo } from "../../../../../Message/Game/SPetInfo";
import { FilterConst } from "../../../../component/gconst/FilterConst";
import { PetMingBaseItem } from "./PetMingBaseItem";
import { ItemData } from "../../../resource/info/ItemData";
import { EPlayerItemPosType } from "../../../../../Message/Public/EPlayerItemPosType";
import { DragEvent } from "../../../../../com/mui/events/DragEvent";
import { ObjCreate } from "../../common/ObjCreate";
import { ResFileConst } from "../../../resource/ResFileConst";
import { LoaderHelp } from "../../../../common/display/LoaderHelp";
import { Cache } from "../../../cache/Cache";
import { Dispatcher } from "../../../../mvc/core/Dispatcher";
import { DataEvent } from "../../../events/DataEvent";
import { EventName } from "../../../mvc/EventName";
import { Language } from "../../../../../extend/language/Language";
import { GameConst } from "../../../../component/gconst/GameConst";
import { GLoadedButton } from "../../../../../com/mui/controls/GLoadedButton";
type int = number;
//class PetMingEquipItem
    
    export  class PetMingEquipItem /* flash.display.Sprite */
    {
        constructor(arg1: int)
        {
            
            this._canOpenIndex = arg1;
            this.init();
            this.doubleClickEnabled = true;
            this.addEventListener(flash.events.MouseEvent.DOUBLE_CLICK, this.onDoubleClickHandler);
            return;
        }

        public get canOpenIndex(): int
        {
            return this._canOpenIndex;
        }

        public get itemData(): PetMingItemData
        {
            return this._itemData;
        }

        public get posType(): int
        {
            return this._posType;
        }

        public set posType(arg1: int)
        {
            this._posType = arg1;
            this._mingItem.posType = arg1;
            return;
        }

        public get posIndex(): int
        {
            return this._posIndex;
        }

        public set posIndex(arg1: int)
        {
            this._posIndex = arg1;
            this._mingItem.posIndex = arg1;
            return;
        }

        public get isEnable(): Boolean
        {
            return this._isEnable;
        }

        public set isEnable(arg1: Boolean)
        {
            this._isEnable = arg1;
            if (this._isEnable) 
            {
                this._enableBitmap.bitmapData = null;
                this._mingItem.toolTipData = null;
            }
            else 
            {
                if (this._isLoaded) 
                {
                    this._enableBitmap.bitmapData = GlobalClass.getBitmapData(ImagesConst.PetMingPosFeng);
                }
                this._mingItem.toolTipData = this.getToolTipData();
            }
            return;
        }

        public set petInfo(arg1: SPetInfo)
        {
            if (!this._isEnable) 
            {
                this._mingItem.toolTipData = this.getToolTipData();
            }
            return;
        }

        public set itemData(arg1: PetMingItemData)
        {
            this._itemData = arg1;
            this._mingItem.itemData = arg1;
            this._mingItem.toolTipData = this._mingItem.toolTipData;
            if (arg1) 
            {
                if (arg1.isMax) 
                {
                    this._levelUpBtn.visible = false;
                }
                else 
                {
                    if (arg1.isCanUpgrade) 
                    {
                        this._levelUpBtn.filters = [];
                    }
                    else 
                    {
                        this._levelUpBtn.filters = [FilterConst.colorFilter];
                    }
                    this._levelUpBtn.visible = true;
                }
                this._levelUpBtn.toolTipData = this.getLevelUpBtnTip();
            }
            else 
            {
                this._levelUpBtn.visible = false;
            }
            return;
        }

        public move(arg1: int, arg2: int): void
        {
            this.x = arg1;
            this.y = arg2;
            return;
        }

        protected init(): void
        {
            this._enableBitmap = new Object /* flash.display.Bitmap */();
            this._enableBitmap.x = 25;
            this._enableBitmap.y = 13;
            this.addChild(this._enableBitmap);
            this._mingItem = new PetMingBaseItem();
            this._mingItem._nameTxt.x = 0;
            this._mingItem._nameTxt.width = 80;
            this._mingItem._nameTxt.autoSize = flash.text.TextFieldAutoSize.CENTER;
            this._mingItem._levelTxt.x = 0;
            this._mingItem._levelTxt.width = 80;
            this._mingItem._levelTxt.autoSize = flash.text.TextFieldAutoSize.CENTER;
            this._mingItem._effectSprite.x = 39;
            this._mingItem.setSize(80, 54);
            this._mingItem.doubleClickEnabled = true;
            this._mingItem.toolTipType = ItemData.ToolTipType_PetLifeStyleEquip;
            this._mingItem.posType = EPlayerItemPosType._EPlayerItemPosTypePetEquipBase;
            this._mingItem.addEventListener(DragEvent.Event_Move_In, this.onMoveInMingPosItemHandler);
            this.addChild(this._mingItem);
            this._levelUpBtn = ObjCreate.createGLoadedButton(ResFileConst.PetMingLevelUpBtn, 60, 42, 19, 18, this);
            this._levelUpBtn.addEventListener(flash.events.MouseEvent.CLICK, this.onLevelUpBtnClickHandler);
            this._levelUpBtn.visible = false;
            LoaderHelp.addResCallBack(ResFileConst.PetMing, this.onLoadedHandler);
            return;
        }

        /* internal  */onMoveInMingPosItemHandler(arg1: DragEvent): void
        {
            var loc4=null;
            if (!this._isEnable) 
            {
                return;
            }
            var loc1=arg1.dragItem as PetMingBaseItem;
            var loc2=arg1.dropItem as PetMingBaseItem;
            var loc3;
            if (loc3 = Cache.instance.petMing.currentPetInfo) 
            {
                if (loc1 && loc2) 
                {
                    loc4 = loc1.dragSource as ItemData;
                    if (loc1.posType == EPlayerItemPosType._EPlayerItemPosTypePetLifeStypePut && loc2.posType == EPlayerItemPosType._EPlayerItemPosTypePetEquipBase) 
                    {
                        Dispatcher.dispatchEvent(new DataEvent(EventName.PetMingDress, {"petUid": loc3.uid, "itemUid": loc4.uid, "index": loc2.posIndex}));
                    }
                }
            }
            return;
        }

        /* internal  */onLoadedHandler(): void
        {
            this._isLoaded = true;
            if (this._isEnable) 
            {
                this._enableBitmap.bitmapData = null;
            }
            else 
            {
                this._enableBitmap.bitmapData = GlobalClass.getBitmapData(ImagesConst.PetMingPosFeng);
            }
            return;
        }

        /* internal  */onLevelUpBtnClickHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            var loc1=null;
            if (this._itemData.isCanUpgrade) 
            {
                loc1 = Cache.instance.petMing.currentPetInfo;
                if (loc1 && this._itemData) 
                {
                    Dispatcher.dispatchEvent(new DataEvent(EventName.PetMingUpgrade, {"petUid": loc1.uid, "itemUid": this._itemData.uid}));
                }
            }
            return;
        }

        /* internal  */getLevelUpBtnTip(): string
        {
            var loc1=null;
            var loc2=null;
            if (!this._itemData.isMax) 
            {
                loc1 = "<font color=\'#f0ea3f\'>" + Language.getString(54754) + "</font>\n" + this._itemData.getAttrDesc("\n", true);
                loc2 = this._itemData.isExpEnough ? "#ffffff" : "#ff0000";
                loc1 = loc1 + ("\n<font color=\'#f0ea3f\'>" + Language.getString(54757) + "</font>" + "<font color=\'" + loc2 + "\'>" + (this._itemData.upgradeExp - this._itemData.lsExp) + "</font>");
                if (this._itemData.isExpEnough) 
                {
                    loc1 = loc1 + Language.getString(54758);
                }
                else 
                {
                    loc1 = loc1 + Language.getString(54759);
                }
            }
            return loc1;
        }

        /* internal  */onDoubleClickHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            var loc1=Cache.instance.petMing.currentPetInfo;
            if (loc1 && this._itemData) 
            {
                Dispatcher.dispatchEvent(new DataEvent(EventName.PetMingUnDress, {"petUid": loc1.uid, "bagUid": this._itemData.uid}));
            }
            return;
        }

        public getToolTipData(): string
        {
            var loc2=0;
            var loc3=0;
            var loc4=null;
            var loc1=Cache.instance.petMing.currentPetInfo;
            if (this._isEnable) 
            {
                return null;
            }
            if (loc1) 
            {
                loc2 = GameConst.MinPetLevelForLifestyle;
                loc3 = GameConst.AddCountEveryPetLevel;
                if (this._canOpenIndex != 0) 
                {
                    if (this._canOpenIndex != 1) 
                    {
                        if (this._canOpenIndex != 2) 
                        {
                            if (this._canOpenIndex != 3) 
                            {
                                if (this._canOpenIndex == 4) 
                                {
                                    loc4 = Language.getStringByParam(54760, loc2 + 4 * loc3, 1);
                                }
                            }
                            else 
                            {
                                loc4 = Language.getStringByParam(54760, loc2 + 3 * loc3, 1);
                            }
                        }
                        else 
                        {
                            loc4 = Language.getStringByParam(54760, loc2 + 2 * loc3, 1);
                        }
                    }
                    else 
                    {
                        loc4 = Language.getStringByParam(54760, loc2 + loc3, 1);
                    }
                }
                else 
                {
                    loc4 = Language.getStringByParam(54760, loc2, 4);
                }
                return loc4;
            }
            return null;
        }

        protected /* var */_enableBitmap: Object /* flash.display.Bitmap */;

        /* internal */ /* var */_posType: int;

        /* internal */ /* var */_posIndex: int;

        protected /* var */_mingItem: PetMingBaseItem;

        protected /* var */_levelUpBtn: GLoadedButton;

        protected /* var */_itemData: PetMingItemData;

        /* internal */ /* var */_isEnable: Boolean;

        /* internal */ /* var */_isLoaded: Boolean;

        /* internal */ /* var */_canOpenIndex: int=0;
    }
